<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>查看汇报</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/minirefresh.css"/>
    <script src="../../js/mui.min.js"></script>
    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/vue.js"></script>
    <script src="../../js/main.js"></script>
    <script src="../../js/minirefresh.js"></script>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div id="app">
    <header class="mui-bar mui-bar-nav">
        <span class="back" @click="back"></span>
        <h1 class="mui-title">查看汇报</h1>
    </header>
    <div class="mui-content">
        <ul class="report-tab">
            <li>
                <select v-model="type" @change="downCallback">
                    <option v-for="item in types" :value="item.index" v-text="item.name"></option>
                </select>
            </li>
            <li>
                <select v-model="status" @change="downCallback">
                    <option v-for="item in all_status" v-text="item.name"></option>
                </select>
            </li>
        </ul>
        <div id="minirefresh" class="minirefresh-wrap">
            <div class="minirefresh-scroll">
                <p class="report-refresh-info" v-show="re_info">暂无数据</p>
                <ul class="tabs" style="padding-top: 0;padding-bottom: 0;display: none">
                    <li v-for="(item, index) in list" @click="open_detail(index)">
                        <div class="tabs-status" :class="item.status"></div>
                        <div class="report-top report-item">
                            <div class="report-headimg fl" v-text="item.headName"></div>
                            <div class="report-info">
                                <p><span v-text="item.userName"></span><span class="report-type-item daily" v-text="item.type"></span></p>
                                <p v-text="item.time"></p>
                            </div>
                        </div>
                        <p class="tabs-content" v-for="(li,i) in item.content"><span v-text="li.title" style="color: #8f8f94;margin-right: 5px"></span><span v-text="li.words"></span></p>
                        <p class="tabs-info fr"><a>查看详情></a></p>
                        <div class="clear"></div>
                    </li>
                </ul>
            </div>
        </div>
        <ul class="report-footer new-footer">
            <li>
                <a href="report.html">
                    <div>
                        <img src="../../images/report/zhixin_huibao_xhb_icon.png"/>
                    </div>
                    <p>写汇报</p>
                </a>
            </li>
            <li>
                <a href="###">
                    <div>
                        <img src="../../images/report/zhixin_huibao_khb_click_icon.png"/>
                    </div>
                    <p style="color: rgb(44,154,232)">看汇报</p>
                </a>
            </li>
            <div class="clear"></div>
        </ul>
    </div>
</div>
</body>
<script>
    function sendInfoToJava(name) {
        //调用android程序中的方法，并传递参数
        javascript:WebView.showInfoFromJs(name);
    }
    var flag = true;
    var app = new Vue({
        el: "#app",
        data: function () {
            return{
                page: 2,
                pageSize: 4,
                type: 0,
                types: [
                    {name: "全部类型",index: 0},
                    {name: "日报",index: 1},
                    {name: "周报",index: 2},
                    {name: "月报",index: 3}
                ],
                status: "全部状态",
                all_status: [
                    {name: "全部状态"},
                    {name: "我发出的"},
                    {name: "我收到的"}
                ],
                replyLoginName: "",
                createUser: "",
                noCreateUser: "",
                list: [],
                minirefresh: null,
                requestDelayTime: 600,
                re_info: false,
                up_flag: false
            }
        },
        mounted: function() {
            var this_obj = this;
            this_obj.miniRefresh = new MiniRefresh({
                container: '#minirefresh',
                down: {
                    callback: this_obj.downCallback
                },
                up: {
                    isAuto: false,
                    callback: this_obj.upCallback
                }
            });
        },
        methods: {
            back: function () {
                var name = "back";
                sendInfoToJava(name);
            },
            downCallback: function() {
                var this_obj = this;
                setTimeout(function() {
                    this_obj.ready();
                    this_obj.miniRefresh.endDownLoading(true);
                }, this_obj.requestDelayTime);
            },
            upCallback: function() {
                var this_obj = this;
                setTimeout(function() {
                    if(this_obj.up_flag == true) {
                        this_obj.change_type();
                    }
                    this_obj.miniRefresh.endUpLoading(flag);
                }, this_obj.requestDelayTime);
            },
            ready: function () {
                var this_obj = this;
                var url = "/report/zgReports";
                this_obj.createUser = "";
                this_obj.replyLoginName = "";
                this_obj.noCreateUser = "";
                this_obj.up_flag = false;
                if(this_obj.status == "我发出的"){
                    this_obj.replyLoginName = "";
                    this_obj.noCreateUser = "";
                    this_obj.createUser = localStorage.userName;
                }else if(this_obj.status == "我收到的"){
                    this_obj.createUser = "";
                    this_obj.replyLoginName = "shibl";
                    this_obj.noCreateUser = localStorage.userName;
                }
                var data = {
                    "pageNo": 1, //第几页必传
                    "pageSize": this_obj.pageSize,  //页有几个数据必传
                    //"replyLoginName": this_obj.replyLoginName,   //我接受到的 当前人的loginname
                    "noCreateUser": this_obj.noCreateUser,
                    "companyId": localStorage.companyId, //公司ID必传
                    "contentDetails": false, //是否看详情
                    "createUser": this_obj.createUser, //我发出的 当前人的loginname
                    "type": this_obj.type,
                    "loginingName": localStorage.userName
                };
                if(typeof(localStorage.companyId) == "undefined" || typeof(localStorage.userName) == "undefined"){
                    mui.toast("请重新登录");
                }else{
                    common_ajax(url,data,function (res) {
                        if(res.code < 0){
                            mui.toast(res.errorMsg);
                        }else {
                            this_obj.list = [];
                            this_obj.miniRefresh.scroller.scrollTo(0,0);
                            console.log(res);
                            if(res.obj.length == 0){
                                $(".downwrap-content").hide();
                                this_obj.re_info = true;
                                this_obj.up_flag = false;
                                $(".minirefresh-upwrap").hide();
                            }else{
                                this_obj.re_info = false;
                                $(".downwrap-content").show();
                                this_obj.up_flag = true;
                                $(".minirefresh-upwrap").show();
                            }
                            for (var i in res.obj) {
                                var content = [];
                                for (j in res.obj[i].textList) {
                                    var remark;
                                    if(res.obj[i].textList[j]['content'] == ""){
                                        remark = "暂无";
                                    }else{
                                        remark = res.obj[i].textList[j]['content'];
                                    }
                                    content.push({
                                        title: res.obj[i].textList[j]['title'],
                                        words: remark
                                    });
                                }
                                var r_type;
                                if (res.obj[i]['type'] == 1) {
                                    r_type = "日报";
                                } else if (res.obj[i]['type'] == 2) {
                                    r_type = "周报";
                                } else if (res.obj[i]['type'] == 3) {
                                    r_type = "月报";
                                }
                                var time = res.obj[i]['createTime'].substr(0,16);
                                var status;
                                if (res.obj[i]['readText'] == true) {
                                    status = "already";
                                } else {
                                    status = "new";
                                }
                                var headName = res.obj[i]['createUserName'].slice(-2);
                                this_obj.list.push({
                                    id: res.obj[i]['zgReportId'],
                                    time: time,
                                    type: r_type,
                                    status: status,
                                    userName: res.obj[i]['createUserName'],
                                    headName: headName,
                                    content: content,
                                    createUser: res.obj[i]['createUser']
                                });
                            }
                            this_obj.$nextTick(function(){
                                $(".tabs").show();
                            });
                            this_obj.page = 2;
                            if(res.obj.length < this_obj.pageSize){
                                flag = true;
                            }else{
                                flag = false;
                            }
                            console.log(flag);
                        }
                    },function (res) {
                        $("#minirefresh").hide();
                    })
                }
            },
            change_type: function () {
                var this_obj = this;
                var url = "/report/zgReports";
                this_obj.createUser = "";
                this_obj.replyLoginName = "";
                this_obj.noCreateUser = "";
                if(this_obj.status == "我发出的"){
                    this_obj.replyLoginName = "";
                    this_obj.noCreateUser = "";
                    this_obj.createUser = localStorage.userName;
                }else if(this_obj.status == "我收到的"){
                    this_obj.createUser = "";
                    this_obj.replyLoginName = "shibl";
                    this_obj.noCreateUser = localStorage.userName;
                }
                var data = {
                    "pageNo": this_obj.page, //第几页必传
                    "pageSize": this_obj.pageSize,  //页有几个数据必传
                    //"replyLoginName": this_obj.replyLoginName,   //我接受到的 当前人的loginname
                    "noCreateUser": this_obj.noCreateUser,
                    "companyId": localStorage.companyId, //公司ID必传
                    "contentDetails": false, //是否看详情
                    "createUser": this_obj.createUser, //我发出的 当前人的loginname
                    "type": this_obj.type,
                    "loginingName": localStorage.userName
                };
                if(typeof(localStorage.companyId) == "undefined" || typeof(localStorage.userName) == "undefined"){
                    mui.toast("请重新登录");
                }else{
                    common_ajaxs(url,data,function (res) {
                        if(res.code < 0){
                            mui.toast(res.errorMsg);
                        }else {
                            this_obj.re_info = false;
                            $(".downwrap-content").show();
                            for (var i in res.obj) {
                                var content = [];
                                for (j in res.obj[i].textList) {
                                    var remark;
                                    if(res.obj[i].textList[j]['content'] == ""){
                                        remark = "暂无";
                                    }else{
                                        remark = res.obj[i].textList[j]['content'];
                                    }
                                    content.push({
                                        title: res.obj[i].textList[j]['title'],
                                        words: remark
                                    });
                                }
                                var r_type;
                                if (res.obj[i]['type'] == 1) {
                                    r_type = "日报";
                                } else if (res.obj[i]['type'] == 2) {
                                    r_type = "周报";
                                } else if (res.obj[i]['type'] == 3) {
                                    r_type = "月报";
                                }
                                var time = res.obj[i]['createTime'].substr(0,16);
                                var status;
                                if (res.obj[i]['readText'] == true) {
                                    status = "already";
                                } else {
                                    status = "new";
                                }
                                var headName = res.obj[i]['createUserName'].slice(-2);
                                this_obj.list.push({
                                    id: res.obj[i]['zgReportId'],
                                    time: time,
                                    type: r_type,
                                    status: status,
                                    userName: res.obj[i]['createUserName'],
                                    headName: headName,
                                    content: content,
                                    createUser: res.obj[i]['createUser']
                                });
                            }
                            this_obj.page++;
                            setTimeout(function () {
                                if(res.obj.length < this_obj.pageSize){
                                    flag = true;
                                }else{
                                    flag = false;
                                }
                                console.log(flag);
                            },600);
                        }
                    },function (res) {
                        console.log(JSON.stringify(res));
                    })
                }
            },
            open_detail: function (index) {
                var this_obj = this;
                this_obj.list[index]['status'] = "already";
                localStorage.zgReportId = this_obj.list[index]['id'];
                location.href = "my_report.html";
            }
        }
    });
    app.ready();
</script>
</html>